import { tenant } from "@/api/index.js";
import { mapState } from "vuex";
export default {
  data () {
    return {
      flyShow: false,
      flyText: 0,
      pageBatchNum: null,
      navFly: false,
      m: null,
      receiveLoading: false
    };
  },
  computed: {
    ...mapState({
      batchNum: (state) => state.login.batchNum
    })
  },
  methods: {
    timeOut (e) {
      // 延时器
      if (!this.navFly) return;
      setTimeout(() => {
        this.getLog(0);
      }, 1800);
    },
    // 展开接收结果
    getResult (val) {
      clearTimeout(this.m);
      this.navFly = true;
      if (val) return; // 悬停在list上面不重复调接口
      this.getLog(1);
    },
    async getLog (val) {
      // this.navFly = true
      // [val ? "getTaskLog" : "getReadTaskLog"
      let { data } = await tenant.task();
      // .then(res => {
      this.logList = data.records;
      this.pageBatchNum = data.records.length;
      // let num = 0
      // let taskFinishStatus = 0
      data.records.forEach((item) => {
        item.message = "";
        if (item.errors.length) {
          item.errors.forEach((ele, index) => {
            item.message += `${ele.message}${index === item.errors ? "" : "； "
              }`;
          });
        }
      });
      // this.$store.commit('common/FLY_NUM', num)
      // if (taskFinishStatus > 0) this.timeOut()
      // })
    },
    out () {
      this.m = setTimeout(() => {
        this.remove = true
        // this.navFly = false;
      }, 300);
    },
    // 批量飞动画
    addShopCart () {
      this.flyShow = true;
    },
    // 动画钩子函数
    // 进入前状态
    beforeEnter (el) {
      el.style.left = "50%";
      el.style.top = "50%";
      el.style.transform = "scale(1)";
    },
    // 进入中
    enter (el, done) {
      // 需要调用元素的offset操作,才有过渡的效果,否则会马上实现过渡
      el.offsetWidth;
      const flyMsg = document.getElementById("flyMsg");
      const left = parseInt(flyMsg.getBoundingClientRect().x) + 18;
      const top = parseInt(flyMsg.getBoundingClientRect().y) - 21;
      el.style.left = `${left}px`;
      el.style.top = `${top}px`;
      done();
    },
    // 进入后
    afterEnter () {
      let num = Number(JSON.parse(localStorage.batchNum));
      num++;
      this.flyShow = false;
      setTimeout(() => {
        this.$store.commit("common/FLY_NUM", num);
      }, 1000);
    }
  }
};
